package com.ruoyi.wms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.wms.domain.StockInventory;
import com.ruoyi.wms.service.IStockInventoryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 库存盘点Controller
 *
 * @author ruoyi
 * @date 2025-10-24
 */
@Api(value = "库存盘点Controller", tags = "库存盘点Controller")
@RestController
@RequestMapping("/inventory")
public class StockInventoryController extends BaseController {
    @Autowired
    private IStockInventoryService stockInventoryService;

    /**
     * 查询库存盘点列表
     */
    @RequiresPermissions("wms:inventory:list")
    @GetMapping("/list")
    public TableDataInfo list(StockInventory stockInventory) {
        startPage();
        List<StockInventory> list = stockInventoryService.selectStockInventoryList(stockInventory);
        return getDataTable(list);
    }


    /**
     * 获取库存盘点详细信息
     */
    @RequiresPermissions("wms:inventory:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(stockInventoryService.selectStockInventoryById(id));
    }

    /**
     * 修改库存盘点
     */
    @RequiresPermissions("wms:inventory:edit")
    @Log(title = "库存盘点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockInventory stockInventory) {
        return toAjax(stockInventoryService.updateStockInventory(stockInventory));
    }

    /**
     * 删除库存盘点
     */
    @RequiresPermissions("wms:inventory:remove")
    @Log(title = "库存盘点", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody String[] ids) {
        if (ids == null || ids.length == 0) {
            return error("未选中");
        }
        return toAjax(stockInventoryService.deleteStockInventoryByIds(ids));
    }

    @ApiOperation("根据批次号查询盘点")
    @GetMapping(value = "/queryStockInventoryByBatchNum")
    public AjaxResult queryStockInventoryByBatchNum(@ApiParam(value = "批次号", required = true) @RequestParam(value = "batchNum") String batchNum  ) {
        return success(stockInventoryService.selectStockInventoryById(batchNum));
    }

}
